home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13026 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: solon.com!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
  4. Subject: Re: C coding problem
  5. Date: 3 Apr 1996 19:13:07 -0600
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4jv7n3$d8o@solutions.solon.com>
  10. References: <4ianbf$h86@solutions.solon.com> <4io1io$no4@solutions.solon.com> <4j06na$808@solutions.solon.com> <4jttan$3gf@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12.  
  13. In article <4jttan$3gf@solutions.solon.com>,
  14. Niall Smart <nsmart@indigo.ie> wrote:
  15.  >
  16.  >>: I recently wrote a loop that went like this:
  17.  >
  18.  >>: while (p < end_p)
  19.  >>:     ++*p++;
  20.  >
  21.  >>: Maybe some will find it a counter-example; I think it's good
  22.  >>: code that embodies the way C is designed to work.  Arrays are
  23.  >>: second rate objects in C.  Use pointers.
  24.  >
  25.  >That code scores negative for maintainability, why use arcane
  26.  >features of the language that can be replaced with more readable code?
  27.  >If you read any of the books on writing good code you will find
  28.  >hundreds of reasons to avoid code like that. The execution time you
  29.  >*might* be saving is offset many times by the time it takes a
  30.  
  31. Actually you don't really save any execution time compared to using an array
  32. index. Any decent optimizer will turn an array indexing loop into pointer
  33. manipulation. Inserting extra parentheses also won't affect the execution time
  34. either: ++(*(p++))
  35.  
  36.  >maintainer to figure it out.
  37.  
  38. If the maintainer is worth his or her paycheck, he or she will know what it
  39. does by mentally inserting those parentheses: clearly, the thing that p
  40. currently points to is incremented, and p is incremented as well. I wouldn't
  41. hire a C maintainer who didn't know the basic precedence rules of the C
  42. language sufficiently well to know what ++*p++ does, or perhaps I'd arrange for
  43. mandatory comp.lang.c, ISO 9899, K&R and H&S reading if the person otherwise
  44. came with great references and credentials!
  45.  
  46. Which is not to say that we should purposely write maintainer-hostile code! 
  47. This is better for testing the maintainer in an interview more than anything
  48. else.
  49. -- 
  50.